<%inherit file="/en/base.html" />
<%namespace file="/gmap.html" import="*"/>
<h3>My Way</h3>
% if ctx.errors:
<table>
% for k in ctx.msg.keys():
    <tr><td style="text:#FFAAAA"><b>${k}</b></td><td>${ctx.msg[k]}</td></tr>
% endfor
</table>
% endif
<br>
<form action="/myjourney/save" method=post>
% if ctx.edit:
<input type="hidden" value="${ ctx.j.key()}" name="journey">
% endif
<table>
    <tr><td>Public</td><td><input type=checkbox value="on" name="public"
            % if ctx.j.public:
                checked
            % endif
            ></td></tr>
    <tr><td valign=top>Name</td><td><input type="text" name="name" value="${ctx.j.name|h,ctx.h.defnone}" 
    % if ctx.req.get("name"): 
        style="border-color:#FF5555;border-width:medium"
    % endif
    ></td></tr>
    <tr><td>Started on</td><td>${h.input_date("started", value=h.defnone(ctx.j.started))}</td></tr>
    <tr><td>Finished on</td><td>${h.input_date("ended", value=h.defnone(ctx.j.ended))}</td></tr>
    <tr><td>Length</td><td><input type="text" name="length" value="${ctx.j.length|ctx.h.defnone}" ></td></tr>
    <tr>
        <td>Region</td>
        <td>
            <% rnames = dict() %>
            %if ctx.regions.has_key(0):
                <%rnames[0] = "region"%>
            %endif
            %if ctx.regions.has_key(1):
                <%rnames[0] = "region0"%>
                <%rnames[1] = "region"%>
            %endif
            %if ctx.regions.has_key(2):
                <%rnames[2] = "region"%>
                <%rnames[1] = "region1"%>
            %endif
            %if ctx.regions.has_key(3):
                <%rnames[3] = "region"%>
                <%rnames[2] = "region2"%>
            %endif
            % if ctx.regions.has_key(0):
                <select name="${rnames[0]}" onchange="submit()">
                    <option value="">Not selected</option>
                % for r in ctx.regions[0]:
                    <option value="${r.key()}"
                    %if ctx.j.region != None and ctx.j.region.key() == r.key() or ctx.j.region and ctx.j.region.get_node(0) and ctx.j.region.get_node(0).key() == r.key():
                        selected
                    %endif
                    >${r.name|h}</option>
                % endfor
                </select>
            % endif
            % if ctx.regions.has_key(1):
                <select name="${rnames[1]}"  onchange="submit()">
                    <option value="">Not selected</option>
                % for r in ctx.regions[1]:
                    <option value="${r.key()}"
                    %if ctx.j.region != None and ctx.j.region.key() == r.key() or ctx.j.region and ctx.j.region.get_node(1) and ctx.j.region.get_node(1).key() == r.key():
                        selected
                    %endif
                    >${r.name|h}</option>
                % endfor
                </select>
            % endif
            % if ctx.regions.has_key(2):
                <select name="${rnames[2]}"  onchange="submit()">
                    <option value="">Not selected</option>
                % for r in ctx.regions[2]:
                    <option value="${r.key()}"
                    %if ctx.j.region != None and ctx.j.region.key() == r.key() or ctx.j.region and ctx.j.region.get_node(2) and ctx.j.region.get_node(2).key() == r.key():
                        selected
                    %endif
                    >${r.name|h}</option>
                % endfor
                </select>
            % endif
            % if ctx.regions.has_key(3):
                <select name="${rnames[3]}"  onchange="submit()">
                    <option value="">Not selected</option>
                % for r in ctx.regions[3]:
                    <option value="${r.key()}"
                    %if ctx.j.region != None and ctx.j.region.key() == r.key():
                        selected
                    %endif
                    >${r.name|h}</option>
                % endfor
                </select>
            % endif
        </td>
        
    </tr>
    <tr><td valign=top>Description</td><td><textarea name="desc" cols=70 rows=15>${ctx.j.desc|h,ctx.h.defnone}</textarea></td></tr>
    <tr><td colspan="2"><input type=submit name=action value="Save"></td></tr>
</table>
</form>

<%def name="context_menu()">
% if ctx.edit:
<a href="/waypoints?journey=${ctx.j.key()}">Edit waypoints</a>
% endif
</%def>
